/*
 * CTexture.h
 *
 *  Created on: Sep 5, 2011
 *      Author: welcome
 */

#ifndef CTEXTURE_H_
#define CTEXTURE_H_

#include <libpng12/png.h>
#include <GLES/gl.h>
#include <KD/kd.h>
#include <stdlib.h>

namespace GGEngine {

typedef enum ExtType{
	PNG_FILE,
	UNKNOWN_TYPE
}ExtType;

class CTexture {
public:

	/**
	 * Width of the image.
	 */
	GLuint width;
	/**
	 * Height of the image.
	 */
	GLuint height;
	/**
	 * Pixel data of the image.
	 */
	png_bytep* pixelData;

	/**
	 * Format of the pixel data.
	 */
	GLenum format;

	/**
	 * Default constructor.
	 */
	CTexture();

	/**
	 * Destructor.
	 */
	virtual ~CTexture();

	/**
	 * Reset the texture image and free the memory.
	 */
	GLvoid reset(void);

	KDint loadTexture(const KDchar* filename, ExtType type);

private:
	/*
	 * Read an PNG texture file
	 */
	KDint ReadPngFile(const KDchar* filename);

	png_structp png_ptr;
	png_infop info_ptr;
	png_byte color_type;
	png_byte bit_depth;
	KDint channels;

};

} /* namespace GGEngine */
#endif /* CTEXTURE_H_ */
